package cz.anime.ppro.beans;

import java.util.Calendar;
import java.util.List;

import javax.faces.bean.ManagedBean;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.web.context.WebApplicationContext;

import cz.anime.ppro.logic.FragmentComponent;
import cz.anime.ppro.model.Fragment;

@Component
@ManagedBean
@Scope(WebApplicationContext.SCOPE_REQUEST)
public class CreateFragmentBean {

	@Autowired
	private FragmentComponent fragmentComponent;

	private List<Fragment> fragments;

	private String description;
	private String title;

	public String createFragment(){
		Fragment fragment = new Fragment();
		fragment.setDate(Calendar.getInstance().getTime());
		fragment.setDescription(description);
		fragment.setTitle(title);
		
		fragmentComponent.save(fragment);
		
		return "admin-fragments?faces-redirect=true";
	}
	
	public List<Fragment> getFragments() {
		return fragments;
	}

	public void setFragments(List<Fragment> fragments) {
		this.fragments = fragments;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

}
